package cn.stylefeng.guns.modular.rest.hxErrorPick;


import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxErrorPick;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxErrorPickMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxErrorPickParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxErrorPickResult;
import cn.stylefeng.guns.modular.hx.storage.service.HxErrorPickService;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Controller
@RequestMapping("/rest/HxErrorPick")
public class restHxErrorPickController {

    @Autowired
    private UserAop userAop;
    @Autowired
    private HxErrorPickService HxErrorPickService;


    /**
     *
     * 查询待处理
     *
     * @author lww
     * @Date 2023-11-7
     */
    @ResponseBody
    @RequestMapping("/findAppDaichuliPageBySpec")
    public LayuiPageInfo findAppDaichuliPageBySpec(HxErrorPickParam hxErrorPickParam) {
        User user = userAop.getUser();
        hxErrorPickParam.setOperateId(user.getOperateId());
        hxErrorPickParam.setStatus("待处理");
        hxErrorPickParam.setDeptId(user.getDeptId());
        hxErrorPickParam.setStorageUser(user.getAccount());
        return HxErrorPickService.findAppDaichuliPageBySpec(hxErrorPickParam);
    }
    /**
     *
     * 查询已处理
     * @author lww
     * @Date 2023-11-7
     */
    @ResponseBody
    @RequestMapping("/appfindyichuli")
    public LayuiPageInfo appfindyichuli(HxErrorPickParam hxErrorPickParam) {
        User user = userAop.getUser();
        hxErrorPickParam.setStatus("已处理");
        hxErrorPickParam.setDeptId(user.getDeptId());
        hxErrorPickParam.setOperateId(user.getOperateId());
        hxErrorPickParam.setDeliverId(user.getDeliverId());
        hxErrorPickParam.setStorageUser(user.getAccount());
        return HxErrorPickService.findAppDaichuliPageBySpec(hxErrorPickParam);
    }


    /**
     * 处理
     *  * @author lww
     *  * @Date 2023-11-7
     */
    @ResponseBody
    @RequestMapping("/receive")
    public ResponseData receive(HxErrorPickParam hxErrorPickParam) {
        User user = userAop.getUser();

        HxErrorPick hxErrorPick = HxErrorPickService.getById(hxErrorPickParam.getId());
        if (hxErrorPick.getStatus().equals("待处理")) {
            hxErrorPickParam.setStatus("已处理");
            hxErrorPickParam.setOperateId(user.getOperateId());
            HxErrorPickService.update(hxErrorPickParam);
        } else {
            return ResponseData.error("任务已无法处理");
        }
        return ResponseData.success();
    }

    @ResponseBody
    @RequestMapping("/findAppweibiaoshuPageBySpec")
    public Integer findAppweibiaoshuPageBySpec() {
        User user = userAop.getUser();
//        Integer count = HxErrorPickService.lambdaQuery()
//                .eq(HxErrorPick::getStatus,"待处理")
//                .eq(HxErrorPick::getStorageUser,user.getAccount())
//                .count();
        QueryWrapper<HxErrorPick> queryWrapper = new QueryWrapper<HxErrorPick>();
        queryWrapper.eq("status","待处理");
        queryWrapper.eq("storage_user",user.getAccount());
        int count = HxErrorPickService.count(queryWrapper);
        return count;
    }

}
